/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tk.zater.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 *
 * @author zater
 */
public class ShowClass {

    public void show(String name) throws Exception {
        Class show = Class.forName(name);

        Constructor[] con = show.getDeclaredConstructors();
        for (int i = 0; i < con.length; i++) {
            System.out.println(con[i].toString());
        }

        Field[] field = show.getDeclaredFields();
        for (int i = 0; i < field.length; i++) {

            System.out.println(field[i].toString() + field[i]);

        }
        Method[] methods = show.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i].toString());
        }
    }

    public void show(String name, Object obj) throws Exception {
        Class show = Class.forName(name);

        Constructor[] con = show.getDeclaredConstructors();
        for (int i = 0; i < con.length; i++) {
            System.out.println(con[i].toString());
        }

        Field[] field = show.getDeclaredFields();
        for (int i = 0; i < field.length; i++) {
            System.out.println(field[i].get(obj));
            System.out.println(field[i].toString() + field[i]);

        }
        Method[] methods = show.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i].toString());
        }
    }

    public String backup(String name, Object obj) throws Exception {
        Class show = Class.forName(name);
        StringBuffer buf = new StringBuffer();
        Field[] field = show.getDeclaredFields();
        for (int i = 0; i < field.length; i++) {
            buf.append(field[i].getName() +" "+ field[i].get(obj));

        }
        return buf.toString();
    }

}
